<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 给定一个非空整数数组，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素。
        var singleNumber1 = function (nums) {
            let a = ''
            for (var i = 0; i < nums.length; i++) {
                for (var j = i + 1; j < nums.length; j++) {
                    if (nums[i] === nums[j]) {
                        nums[i] = nums[j] = ''
                        for (var k = 0; k < nums.length; k++) {
                            if (nums[k]) {
                                a = nums[k]
                            }
                        }
                    }
                }
            }
            return a
        }
        const res1 = singleNumber1([1])
        console.log(res1) // 7

        // 找出所有只出现了一次的元素
        var singleNumber2 = function (nums) {
            let arr = []
            for (var i = 0; i < nums.length; i++) {
                for (var j = i + 1; j < nums.length; j++) {
                    if (nums[i] === nums[j]) {
                        nums[i] = nums[j] = ''
                        arr = nums
                    }
                }
            }
            return arr
        }
        const res2 = singleNumber2([4, 1, 2, 8, 2, 4, 5, 5, 7])
        const newArr = []
        for (var k = 0; k < res2.length; k++) {
            if (res2[k]) {
                newArr.push(res2[k])
            }
        }
        const newRes = newArr.join(',')
        console.log(newRes) // 1,8,7
    </script>
</head>

<body>

</body>

</html>